import * as sdk from './fetch';

const controllerName = 'shopController';

/**
 *
 * 商城消息
 *
 */
async function getInfoNums(params): Promise<wmBaseResponseString> {
  let result = await sdk.post<wmBaseResponseString>(`appMessage/page`, {
    ...params,
  });
  return result;
}

/**
 *
 * 商城购物车
 *
 */
async function getCartNums(params): Promise<wmBaseResponseString> {
  let result = await sdk.post<wmBaseResponseString>(`site/purchaseInfo`, {
    ...params,
  });
  return result;
}

/**
 *
 * 订单角标
 *
 */
async function findOrderCount(params): Promise<wmBaseResponseString> {
  let result = await sdk.get<wmBaseResponseString>(`trade/todo/null`, {
    ...params,
  });
  return result.context;
}

export default {
  getInfoNums,
  getCartNums,
  findOrderCount,
};

/**
 * 列表数据
 */
export interface esGoodsInfoPage {
  esGoodsInfoPage?: esGoodsInfoPageDetail;
  [k: string]: any;
}
export interface esGoodsInfoPageDetail {
  /**
   * 具体数据内容
   */
  content?: ContentDetailVO[];
  empty?: boolean;
  first?: boolean;
  last?: boolean;
  /**
   * 页码
   */
  number?: number;
  numberOfElements?: number;
  /**
   * 每页条数
   */
  size?: number;
  sort?: null;
  /**
   * 总数据大小
   */
  total?: number;
  totalElements?: number;
  totalPages?: number;
  [k: string]: any;
}

export interface ContentDetailVO {
  goodsInfo?: goodsInfoDetailVO[];
  id?: number;
}

export interface goodsInfoDetailVO {
  goodsInfoImg?: string;
  goodsInfoName?: string;
  marketPrice?: number;
}

/**
 * 万米请求返回
 */
export interface wmBaseResponseString {
  /**
   * 结果码
   */
  code: string;
  /**
   * 内容
   */
  context?: esGoodsInfoPage;
  /**
   * 错误内容
   */
  errorData?: {
    [k: string]: any;
  };
  /**
   * 状态
   */
  success?: boolean;
  /**
   * 消息内容
   */
  message?: string;
  [k: string]: any;
}

/**
 * 正常请求返回
 */
export interface BaseResponseString {
  /**
   * 结果码
   */
  code: string;
  /**
   * 内容
   */
  data?: {
    [k: string]: any;
  };
  /**
   * 错误内容
   */
  errorData?: {
    [k: string]: any;
  };
  /**
   * 状态
   */
  success?: boolean;
  /**
   * 消息内容
   */
  message?: string;
  [k: string]: any;
}
